package com.jyxd.web.task;

import com.jyxd.web.dao.basic.CommonSettingDao;
import com.jyxd.web.data.basic.CommonSetting;
import com.jyxd.web.data.basic.QuartzTask;
import com.jyxd.web.data.user.User;
import com.jyxd.web.service.assessment.basic.VitalSignMergeService;
import com.jyxd.web.util.DateUtil;
import com.jyxd.web.util.SpringUtil;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.Map;

/**
 * 护理文书生命体征同步job
 */
public class NursingVitalSignsJob implements Job {

    private static Logger logger= LoggerFactory.getLogger(HISQualityControlJob.class);
    //定义一个成员变量
    private static QuartzTask quartzTask;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        VitalSignMergeService vitalSignMergeService = SpringUtil.getBean(VitalSignMergeService.class);
        CommonSettingDao commonSettingDao = SpringUtil.getBean(CommonSettingDao.class);
        Date nextFireTime = jobExecutionContext.getNextFireTime();
        Map<String, String> map = (Map<String, String>) jobExecutionContext.getJobDetail().getJobDataMap().get("map");
        map.put("time", DateUtil.yyyyMMddHHmmssSdfToString(new Date()));
        User user = (User) jobExecutionContext.getJobDetail().getJobDataMap().get("user");
        System.out.println("开始执行");
        try {
            vitalSignMergeService.syncVitalSignMerge(map, user);
            System.out.println("本次执行完毕,本次时间:" + DateUtil.yyyyMMddHHmmssSdfToString(new Date()));
            if (nextFireTime == null) {//说明本任务执行完毕，修改数据库此次任务开关数据
                //关闭此条任务数据库数据
                CommonSetting commonSetting = new CommonSetting();
                commonSetting.setId(map.get("id"));
                commonSetting.setOnOff("1");
                commonSettingDao.updateOnOrOff(commonSetting);

            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
